<?php
namespace app\index\controller;
session_start();
use think\Controller;
use think\Request;
use think\Db;

class Index extends Controller
{
    public function index()
    {

        $data1 = db('l_webshow')->select();
        // var_dump($data);die;
        $data2 = db('l_film')
               ->alias('f')
               ->join('l_sort s','f.id = s.film_id')
               ->field('f.filmname,f.filmimg,s.price,f.id')
               ->where('f.id','=',1)
               ->find();
        // var_dump($data2);die;
        $data3 = db('l_film')
               ->alias('f')
               ->join('l_sort s','f.id = s.film_id')
               ->field('f.filmname,f.filmimg,s.price,f.id')
               ->where('f.id','>',1)
               ->limit(6)
               ->select();

        $data4 = db('l_cinema')->limit(4)->select();
        $this->assign([
            'list1'=>$data1,
            'list2'=>$data2,
            'list3'=>$data3,
            'list4'=>$data4,
            ]);
       

        return view('Index/index');

    }

    public function sou(Request $request)
    {
        $rel = $request->post();

        $data = Db::table('l_film')
                ->whereLike('filmname', '%'.$rel['txt'].'%')
                ->select();

        $stmt = Db::table('l_cinema')
                ->whereLike('cinema', '%'.$rel['txt'].'%')
                ->select();

        $arr = [];
        foreach($stmt as $v){
            $list = Db::table('l_sort')
                    ->alias('ls')
                    ->field('lf.filmname')
                    ->where('ls.cinema_id', $v['id'])
                    ->join('l_film lf', 'ls.film_id=lf.id')
                    ->select();
            $v['film'] = $list;
            $arr[] = $v;
        }

        $num = count($data) + count($arr);
        return view('Sou/index', [
            'data'=>$data,
            'list'=>$arr,
            'num'=>$num,
            'sou'=>$rel['txt']
        ]);
    }

}
